
clear all
************************************
*Numeric Export disabled
local TEX ""
local TEXON 0 //Change "0" to "1" to enable exporting numeric results to .txt files
if !`TEXON' local TEX "*"
*Also need to install texresults2
*ssc install texresults2
************************************
************************************
*Figure Export disabled
local FIG ""
local FIGON 0 //Change "0" to "1" to enable exporting figures (RELEVANT FOLDERS MUST FIRST BE CREATED)
if !`FIGON' local FIG "*"
************************************

*************************************************************************************************
*************************************************************************************************
*Gender Gaps in Policy Responsiveness
*Nolan Kopkin and Andrew Robers
*Political Research Quarterly
*2022
*************************************************************************************************
*************************************************************************************************

***************************************
*Make sure working directory is set
***************************************

*It appears that Kopkin and Roberts use the updated data from Gilens, posted in 2015,
*so I use those data with this analysis
*https://www.russellsage.org/datasets/economic-inequality-and-political-representation
use "Enns_SociologicalScience_Reproduction\DS1_v2.dta", clear



************************************************************
************************************************************
**Code percent support male and female and log odds
*Code with Switcher
gen male_percfav = male_fav/(male_fav+male_opp) if switcher==0 | switcher==.
replace male_percfav = male_opp/(male_fav+male_opp) if switcher==1 

gen male_percfav_lor = log(male_percfav/(1-male_percfav))
label var male_percfav_lor "log of odds: male_percfav"
**
gen female_percfav = female_fav/(female_fav+female_opp) if switcher==0 | switcher==.
replace female_percfav = female_opp/(female_fav+female_opp) if switcher==1

gen female_percfav_lor = log(female_percfav/(1-female_percfav))
label var female_percfav_lor "log of odds: female_percfav"
************************************************************
************************************************************

*************************
*Correlation across preferences
cor male_percfav female_percfav
mat def cor = r(C)
local gendercor = cor[2,1]
*************************


*****************
**Recode outcome so dichotomous
*****************

gen policyadopted =.
recode policyadopted .=0 if OUTCOME==0
recode policyadopted .=1 if OUTCOME==2
recode policyadopted .=1 if OUTCOME==3
recode policyadopted .=1 if OUTCOME==4


**Code Male Female Group Intercept Indicator 
quietly: gen dif_male_female_08=.
quietly: recode dif_male_female_08 .=1 if (male_percfav - female_percfav)>=.08
quietly: recode dif_male_female_08 .=0 if (female_percfav - male_percfav)>=.08

label var dif_male_female_08 ">=8% dif b/t male and female preferences"

label define diflbl 0 "0 male more supportive" 1 "1 female more supportive"
label values dif_male_female_08 diflbl

*******************************************************************
**save data as temporary file to be used for CEM analysis below 
tempfile Gender_CEM
save "`Gender_CEM'", replace
*******************************************************************

***************************************************************************************
***************************************************************************************
*PLOT RELATIONSHIP BETWEEN FEMALE PREFERENCES AND POLICY RESPONSIVENESS
*Figure 4b
***************************************************************************************
***************************************************************************************
{
gen male_perc = 100*male_percfav
gen female_perc = 100*female_percfav

logit policyadopted female_percfav_lor  if  abs(male_percfav - female_percfav)>=.08
mat define b = get(_b)
gen yhatfemale=exp(b[1,2]+(b[1,1]*female_percfav_lor))/(1+exp(b[1,2]+(b[1,1]*female_percfav_lor))) if e(sample)
mat drop b

logit policyadopted female_percfav_lor  if (male_percfav - female_percfav)>=.08
mat define b = get(_b)
gen yhatfemale_lesser=exp(b[1,2]+(b[1,1]*female_percfav_lor))/(1+exp(b[1,2]+(b[1,1]*female_percfav_lor))) if e(sample)
mat drop b

logit policyadopted female_percfav_lor  if (female_percfav - male_percfav)>=.08
mat define b = get(_b)
gen yhatfemale_greater=exp(b[1,2]+(b[1,1]*female_percfav_lor))/(1+exp(b[1,2]+(b[1,1]*female_percfav_lor))) if e(sample)



local bins=40 
twoway ///
(histogram female_perc if (female_perc - male_perc)>8 & policyadopted!=., freq fcolor(navy%80) ///
lcolor(black) lwidth(vvthin) bin(`bins') yaxis(1)) ///
(histogram female_perc if (male_perc - female_perc)>8 & policyadopted!=., /// 
freq fcolor(orange%60) lwidth(vvthin) lcolor(black) lwidth(vvthin) bin(`bins') yaxis(1) ///
ytitle("Frequency", size(medlarge) axis(1)) ylabel(0(5)15, nogrid notick axis(1)) ///
yscale(lwidth(none) r(0 15))) ///
(scatter yhatfemale female_perc, yaxis(2) msize(medsmall) mcolor(black) mlcolor(none) ///
ytitle("Predicted Probability of Policy Change", ///
size(medlarge) axis(2)) ylabel(0(.2)1, nogrid notick axis(2))) ///
(scatter yhatfemale_lesser female_perc, yaxis(2) msize(medsmall) mcolor(orange%80) mlcolor(none)) ///
(scatter yhatfemale_greater female_perc, yaxis(2) msize(medsmall) mcolor(navy%90) mlcolor(none)), ///
xtitle("Percent Favoring Policy Change (Women)", ///
size(medlarge)) graphregion(fcolor(white) lcolor(white)) ///
plotregion(lcolor(black) lwidth(medium)) ///
xlabel(10[10]90, nogrid) xscale(lwidth(none) r(5 95)) ///
yscale(lwidth(none) r(0 1)) legend(off) ///
ysize(3) xsize(4) ///
text(16.8 82 "Female respondents" "more supportive" "than male respondents" "(female - male)>8%") ///
text(16 20 "Male respondents" "more supportive" "than female respondents" "(male - female)>8%") ///
text(5.3 52. "{bf:{it:Combined}}", size(large) color(black)) 
 


`FIG'graph export Figures/predictedfemale.eps, replace
`FIG'graph export Figures/predictedfemale.pdf, as(pdf) replace
}


***************************************************************************************
***************************************************************************************
*PLOT RELATIONSHIP BETWEEN MALE PREFERENCES AND POLICY RESPONSIVENESS
*Figure 4a
***************************************************************************************
***************************************************************************************
{
logit policyadopted male_percfav_lor  if  abs(male_percfav - female_percfav)>=.08
mat define b = get(_b)
gen yhatmale=exp(b[1,2]+(b[1,1]*male_percfav_lor))/(1+exp(b[1,2]+(b[1,1]*male_percfav_lor))) if e(sample)
mat drop b

logit policyadopted male_percfav_lor  if (male_percfav - female_percfav)>=.08
mat define b = get(_b)
gen yhatmale_greater=exp(b[1,2]+(b[1,1]*male_percfav_lor))/(1+exp(b[1,2]+(b[1,1]*male_percfav_lor))) if e(sample)
mat drop b

logit policyadopted male_percfav_lor  if (female_percfav - male_percfav)>=.08
mat define b = get(_b)
gen yhatmale_lesser=exp(b[1,2]+(b[1,1]*male_percfav_lor))/(1+exp(b[1,2]+(b[1,1]*male_percfav_lor))) if e(sample)


local bins=40 
twoway ///
(histogram male_perc if (female_perc - male_perc)>8 & policyadopted!=., freq fcolor(navy%80) ///
lcolor(black) lwidth(vvthin) bin(`bins') yaxis(1)) ///
(histogram male_perc if (male_perc - female_perc)>8 & policyadopted!=., /// 
freq fcolor(orange%60) lwidth(vvthin) lcolor(black) lwidth(vvthin) bin(`bins') yaxis(1) ///
ytitle("Frequency", size(medlarge) axis(1)) ylabel(0(5)15, nogrid notick axis(1)) ///
yscale(lwidth(none) r(0 15))) ///
(scatter yhatmale male_perc, yaxis(2) msize(medsmall) mcolor(black) mlcolor(none) ///
ytitle("Predicted Probability of Policy Change", ///
size(medlarge) axis(2)) ylabel(0(.2)1, nogrid notick axis(2))) ///
(scatter yhatmale_greater male_perc, yaxis(2) msize(medsmall) mcolor(orange%80) mlcolor(none)) ///
(scatter yhatmale_lesser male_perc, yaxis(2) msize(medsmall) mcolor(navy%90) mlcolor(none)) ///
(pcarrowi 13 76 11 70.5, lcolor(black) mcolor(black) lwidth(thin)) /// female>
(pcarrowi 12.5 24 10 32, lcolor(black) mcolor(black) lwidth(thin)), /// male>
xtitle("Percent Favoring Policy Change (Men)", ///
size(medlarge)) graphregion(fcolor(white) lcolor(white)) ///
plotregion(lcolor(black) lwidth(medium)) ///
xlabel(10[10]90, nogrid) xscale(lwidth(none) r(5 95)) ///
yscale(lwidth(none) r(0 1)) legend(off) ///
ysize(3) xsize(4) ///
text(14.5 82 "Female respondents" "more supportive" "than male respondents" "(female - male)>8%") ///
text(14 22 "Male respondents" "more supportive" "than female respondents" "(male - female)>8%") ///
text(3.9 42 "{bf:{it:Combined}}", size(large))

`FIG'graph export Figures/predictedmale.eps, replace
`FIG'graph export Figures/predictedmale.pdf, as(pdf) replace
} 
***************************************************************************************


*********************************************
*********************************************
*Appendix Table A-3
*Replication of Kopkin and Roberts
*********************************************

*men
logit policyadopted male_percfav_lor if abs(male_percfav-female_percfav)>=0.08
estimates store male
local KRnmale = e(N)
*women
logit policyadopted female_percfav_lor if abs(male_percfav-female_percfav)>=0.08
estimates store female
local KRnfemale = e(N)
suest male female, r
*save coefficients as matrix
mat def b =  e(b)
*take sqrt of var to save standard errors
mat def var =  e(V)
mata:
A = st_matrix("var")
B = sqrt(A)
st_matrix("B", B)
end
mat se = vecdiag(B)
*male
local KRcoefmale = b[1,1]
local KRsemale = se[1,1]
local KRconsmale = b[1,2]
local KRconssemale = se[1,2]
*female
local KRcoeffemale = b[1,3]
local KRsefemale = se[1,3]
local KRconsfemale = b[1,4]
local KRconssefemale = se[1,4]

*********************************************
****Model Group Intercept
*********************************************
*men
logit policyadopted male_percfav_lor dif_male_female_08 if abs(male_percfav-female_percfav)>=0.08, r
mat def results = r(table)
local KRcoefmaleshared = results[1,1]
local KRsemaleshared = results[2,1]
local KRcoefmaledifshared = results[1,2]
local KRsemaledifshared = results[2,2]
local consmaleshared = results[1,3]
local conssemaleshared = results[2,3]
local KRnmaleshared = e(N)
*women
logit policyadopted female_percfav_lor dif_male_female_08 if abs(male_percfav-female_percfav)>=0.08, r
mat def results = r(table)
local KRcoeffemaleshared = results[1,1]
local KRsefemaleshared = results[2,1]
local KRcoeffemaledifshared = results[1,2]
local KRsefemaledifshared = results[2,2]
local consfemaleshared = results[1,3]
local consfesemaleshared = results[2,3]
local KRnfemaleshared = e(N)

*********************************************
*Export numeric results to .txt file
*Correlation
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(gendercor) result(`gendercor') round(2) replace
*male
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRcoefmale) result(`KRcoefmale') round(2) append //coef
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRsemale) result(`KRsemale') round(2) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRnmale) result(`KRnmale') round(0) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRconsmale) result(`KRconsmale') round(2) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRconssemale) result(`KRconssemale') round(2) append //
*female
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRcoeffemale) result(`KRcoeffemale') round(2) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRsefemale) result(`KRsefemale') round(2) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRconsfemale) result(`KRconsfemale') round(2) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRconssefemale) result(`KRconssefemale') round(2) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRnfemale) result(`KRnfemale') round(0) append //
*Group Intercept: male
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRcoefmaleshared) result(`KRcoefmaleshared') append //coef
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRsemaleshared) result(`KRsemaleshared') append //se
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRcoefmaledifshared) result(`KRcoefmaledifshared') append //coef
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRsemaledifshared) result(`KRsemaledifshared') append //se
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRnmaleshared) result(`KRnmaleshared') round(0) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRconsmaleshared) result(`consmaleshared') round(2) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRconssemaleshared) result(`conssemaleshared') round(2) append //
*Group Intercept: female
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRcoeffemaleshared) result(`KRcoeffemaleshared') append //coef
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRsefemaleshared) result(`KRsefemaleshared') append //se
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRcoeffemaledifshared) result(`KRcoeffemaledifshared') append //coef
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRsefemaledifshared) result(`KRsefemaledifshared') append //se
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRnfemaleshared) result(`KRnfemaleshared') round(0) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRconsfemaleshared) result(`consfemaleshared') round(2) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRconsfesemaleshared) result(`consfesemaleshared') round(2) append //
*********************************************

*********************************************
*CEM analysis below
*********************************************


*********************************************************************
*********************************************************************
*MATHISEN 2024, P.1375-1376 AND APPENDIX B1
*********************************************************************
*********************************************************************

*Use Exact version of Gilens' data that Mathisen uses
import excel using "Enns_SociologicalScience_Reproduction\Main dataset for United States, from Gilens 2012.xlsx", clear firstrow

gen policyadopted =.
recode policyadopted .=0 if OUTCOME==0
recode policyadopted .=1 if OUTCOME==2
recode policyadopted .=1 if OUTCOME==3
recode policyadopted .=1 if OUTCOME==4

**Code percent support male and female 
*Code with Switcher
*MATHISEN USES PERCENT (NOT LOG ODDS)
gen male_percfav = MALE_FAV/(MALE_FAV+MALE_OPP) 
replace male_percfav = 1-male_percfav if SWITCHER==1 

gen female_percfav = FEMALE_FAV/(FEMALE_FAV+FEMALE_OPP) 
replace female_percfav = 1-female_percfav if SWITCHER==1

**Code Male Female Group Intercept Indicator 
**Greanter than .1 for Mathisen
quietly: gen dif_male_female=.
quietly: recode dif_male_female .=1 if (male_percfav - female_percfav)>.1
quietly: recode dif_male_female .=0 if (female_percfav - male_percfav)>.1


*******************************************************************
**save data as temporary file to be used for CEM analysis below 
tempfile Mathisen_Gender_CEM
save "`Mathisen_Gender_CEM'", replace
*******************************************************************

*Replicate Mathisen for Appendix Table
*MATHISEN USES OLS (not logit)
*men
reg policyadopted male_percfav  if  abs(male_percfav - female_percfav)>.1
*save constant
mat def results = r(table)
scalar Mconsmale = results[1,2]
scalar Mconssemale = results[2,2]
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mcoefmale) coef(male_percfav) round(3) append //coef
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Msemale) se(male_percfav) round(3) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mnmale) result(e(N)) round(0) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mconsmale) result(Mconsmale) round(3) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mconssemale) result(Mconssemale) round(3) append //
*women
reg policyadopted female_percfav  if  abs(male_percfav - female_percfav)>.1
mat def results = r(table)
scalar Mconsfemale = results[1,2]
scalar Mconssefemale = results[2,2]
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mcoeffemale) coef(female_percfav) round(2) append //coef
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Msefemale) se(female_percfav) round(2) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mnfemale) result(e(N)) round(0) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mconsfemale) result(Mconsmale) round(2) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mconssefemale) result(Mconssefemale) round(2) append //

*********************************************
****Model Group Intercept
*********************************************
*men
reg policyadopted male_percfav dif_male_female if abs(male_percfav-female_percfav)>0.1
mat def results = r(table)
scalar consmaleshared = results[1,3]
scalar conssemaleshared = results[2,3]
scalar conslowmaleshared = results[5,3]
scalar consupmaleshared = results[6,3]
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mcoefmaleshared) coef(male_percfav) append //coef
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Msemaleshared) se(male_percfav) append //se
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mlowmaleshared) lbz(male_percfav) append //lb 
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mupmaleshared) ubz(male_percfav) append //ub
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mcoefmaledifshared) coef(dif_male_female) append //coef
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Msemaledifshared) se(dif_male_female) append //se
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mlowmaledifshared) lbz(dif_male_female) append //lb 
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mupmaledifshared) ubz(dif_male_female) append //ub
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mnmaleshared) result(e(N)) round(0) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mconsmaleshared) result(consmaleshared) round(2) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mconslowmaleshared) result(conslowmaleshared) round(2) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mconsupmaleshared) result(consupmaleshared) round(2) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mconssemaleshared) result(conssemaleshared) round(2) append //
*women
reg policyadopted female_percfav dif_male_female if abs(male_percfav-female_percfav)>0.1
mat def results = r(table)
scalar consfemaleshared = results[1,3]
scalar consfesemaleshared = results[2,3]
scalar consfelowmaleshared = results[5,3]
scalar consfeupmaleshared = results[6,3]
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mcoeffemaleshared) coef(female_percfav) append //coef
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Msefemaleshared) se(female_percfav) append //se
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mlowfemaleshared) lbz(female_percfav) append //lb 
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mupfemaleshared) ubz(female_percfav) append //ub
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mcoeffemaledifshared) coef(dif_male_female) append //coef
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Msefemaledifshared) se(dif_male_female) append //se
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mlowfemaledifshared) lbz(dif_male_female) append //lb 
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mupfemaledifshared) ubz(dif_male_female) append //ub
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mnfemaleshared) result(e(N)) round(0) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mconsfemaleshared) result(consfemaleshared) round(2) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mconsfelowmaleshared) result(consfelowmaleshared) round(2) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mconsfesemaleshared) result(consfesemaleshared) round(2) append //
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mconsfeupmaleshared) result(consfeupmaleshared) round(2) append 



************************************************
***Mathisen: Plot for Female Preferences
*Figure 4d
************************************************

gen male_perc = 100*male_percfav
gen female_perc = 100*female_percfav

reg policyadopted female_percfav  if  abs(male_percfav - female_percfav)>.1
mat define b = get(_b)
gen yhatfemale=b[1,2]+b[1,1]*female_percfav if e(sample)
mat drop b

reg policyadopted female_percfav  if (male_percfav - female_percfav)>.1
mat define b = get(_b)
gen yhatfemale_lesser=b[1,2]+b[1,1]*female_percfav if e(sample)
mat drop b

reg policyadopted female_percfav  if (female_percfav - male_percfav)>.1
mat define b = get(_b)
gen yhatfemale_greater=b[1,2]+b[1,1]*female_percfav if e(sample)

*min and max values in figures
sum female_perc if (female_perc - male_perc)>10 & policyadopted!=.
local femminfemgreater = r(min)
local femmaxfemgreater = r(max)
sum female_perc if (male_perc - female_perc)>10 & policyadopted!=.
local femminmalegreater = r(min)
local femmaxmalegreater = r(max)
sum male_perc if (female_perc - male_perc)>10 & policyadopted!=.
local maleminfemgreater = r(min)
local malemaxfemgreater = r(max)
sum male_perc if (male_perc - female_perc)>10 & policyadopted!=.
local maleminmalegreater = r(min)
local malemaxmalegreater = r(max)

`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(femmaxfemgreater) result(`femmaxfemgreater') round(1) append 
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(malemaxfemgreater) result(`malemaxfemgreater') round(1) append 
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(femmaxmalegreater) result(`femmaxmalegreater') round(1) append 
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(malemaxmalegreater) result(`malemaxmalegreater') round(1) append 

local bins=40 
twoway ///
(histogram female_perc if (female_perc - male_perc)>10 & policyadopted!=., freq fcolor(navy%80) ///
lcolor(black) lwidth(vvthin) bin(`bins') yaxis(1)) ///
(histogram female_perc if (male_perc - female_perc)>10 & policyadopted!=., /// 
freq fcolor(orange%60) lwidth(vvthin) lcolor(black) lwidth(vvthin) bin(`bins') yaxis(1) ///
ytitle("Frequency", size(medlarge) axis(1)) ylabel(0(5)15, nogrid notick axis(1)) ///
yscale(lwidth(none) r(0 15))) ///
(scatter yhatfemale female_perc, yaxis(2) msize(medsmall) mcolor(black) mlcolor(none) ///
ytitle("Predicted Probability of Policy Change", ///
size(medlarge) axis(2)) ylabel(0(.2)1, nogrid notick axis(2))) ///
(scatter yhatfemale_lesser female_perc, yaxis(2) msize(medsmall) mcolor(orange%80) mlcolor(none)) ///
(scatter yhatfemale_greater female_perc, yaxis(2) msize(medsmall) mcolor(navy%90) mlcolor(none)), ///
xtitle("Percent Favoring Policy Change (Women)", ///
size(medlarge)) graphregion(fcolor(white) lcolor(white)) ///
plotregion(lcolor(black) lwidth(medium)) ///
xlabel(10[10]90, nogrid) xscale(lwidth(none) r(5 95)) ///
yscale(lwidth(none) r(0 1)) legend(off) ///
ysize(3) xsize(4) ///
text(14.8 84 "Female respondents" "more supportive" "than male respondents" "(female - male)>10%") ///
text(14.5 17 "Male respondents" "more supportive" "than female respondents" "(male - female)>10%") ///
text(5.7 52 "{bf:{it:Combined}}", size(large))

`FIG'graph export Figures/predictedfemalemathisen.eps, replace
`FIG'graph export Figures/predictedfemalemathisen.pdf, as(pdf) replace

**********
*Male
*Figure 4c
reg policyadopted male_percfav  if  abs(male_percfav - female_percfav)>.1
mat define b = get(_b)
gen yhatmale=b[1,2]+b[1,1]*male_percfav if e(sample)
mat drop b

reg policyadopted male_percfav  if (male_percfav - female_percfav)>.1
mat define b = get(_b)
gen yhatmale_greater=b[1,2]+b[1,1]*male_percfav if e(sample)
mat drop b

reg policyadopted male_percfav  if (female_percfav - male_percfav)>.1
mat define b = get(_b)
gen yhatmale_lesser=b[1,2]+b[1,1]*male_percfav if e(sample)



local bins=40 
twoway ///
(histogram male_perc if (female_perc - male_perc)>10 & policyadopted!=., freq fcolor(navy%80) ///
lcolor(black) lwidth(vvthin) bin(`bins') yaxis(1)) ///
(histogram male_perc if (male_perc - female_perc)>10 & policyadopted!=., /// 
freq fcolor(orange%60) lwidth(vvthin) lcolor(black) lwidth(vvthin) bin(`bins') yaxis(1) ///
ytitle("Frequency", size(medlarge) axis(1)) ylabel(0(5)15, nogrid notick axis(1)) ///
yscale(lwidth(none) r(0 15))) ///
(scatter yhatmale male_perc, yaxis(2) msize(medsmall) mcolor(black) mlcolor(none) ///
ytitle("Predicted Probability of Policy Change", ///
size(medlarge) axis(2)) ylabel(0(.2)1, nogrid notick axis(2))) ///
(scatter yhatmale_greater male_perc, yaxis(2) msize(medsmall) mcolor(orange%80) mlcolor(none)) ///
(scatter yhatmale_lesser male_perc, yaxis(2) msize(medsmall) mcolor(navy%90) mlcolor(none)) ///
(pcarrowi 12.1 77 9.1 72.3, lcolor(black) mcolor(black) lwidth(thin)) /// female>
(pcarrowi 10.6 24 8.5 31.5, lcolor(black) mcolor(black) lwidth(thin)), /// male>
xtitle("Percent Favoring Policy Change (Men)", ///
size(medlarge)) graphregion(fcolor(white) lcolor(white)) ///
plotregion(lcolor(black) lwidth(medium)) ///
xlabel(10[10]90, nogrid) xscale(lwidth(none) r(5 95)) ///
yscale(lwidth(none) r(0 1)) legend(off) ///
ysize(3) xsize(4) ///
text(13.5 84 "Female respondents" "more supportive" "than male respondents" "(female - male)>10%") ///
text(12 20 "Male respondents" "more supportive" "than female respondents" "(male - female)>10%") ///
text(3.85 48 "{bf:{it:Combined}}", size(large))

`FIG'graph export Figures/predictedmalemathisen.eps, replace
`FIG'graph export Figures/predictedmalemathisen.pdf, as(pdf) replace


***************************************************************
***************************************************************
***************************************************************


***************************************************************
*CEM Analysis
***************************************************************

********************************************************
*Kopkin and Roberts
********************************************************
*FEMALE
*Need to open data each time, becuase observations dropped during CEM
program define cem_female
args Gender_CEM
use "`Gender_CEM'", clear

*drop missing differences (less than abs value(8%))
quietly: drop if dif_male_female_08==.

quietly: cem female_percfav if policyadopted!=., tr(dif_male_female_08) k2k
quietly: logit policyadopted female_percfav_lor if cem_matched==1

mat def results = r(table)
scalar female = results[1,1] //coef female_percfav
scalar femalecon = results[1,2] //coef constant
scalar N_female = e(N)
end

*MALE
*Need to open data each time, becuase observations dropped during CEM
program define cem_male

args Gender_CEM
use "`Gender_CEM'", clear

*drop missing differences (less than abs value(8%))
quietly: drop if dif_male_female_08==.

quietly: cem male_percfav if policyadopted!=., tr(dif_male_female_08) k2k
quietly: logit policyadopted male_percfav_lor if cem_matched==1

mat def results = r(table)
scalar male = results[1,1] //coef female_percfav
scalar malecon = results[1,2] //coef constant
scalar N_male = e(N)
end

//set up a new dataset with variable names listed below 
tempfile cem_gender
tempname temp1
postfile `temp1'  female  femalecon  N_female  ///
				 male  malecon  N_male ///
				using "`cem_gender'", replace

*Set seed because CEM randomly drops duplicate matches
*https://www.random.org/
set seed 6951929
//run each program 1000 times 
forval i = 1/1000 {
	
cem_female "`Gender_CEM'"

cem_male "`Gender_CEM'"

//post results from each simulation to data set 
post `temp1' (female) (femalecon) (N_female) ///
			(male) (malecon) (N_male) 
}
postclose `temp1' 


******************************************************************************
*export results 
use "`cem_gender'", clear 


local varlist female femalecon N_female  ///
		male malecon N_male

foreach var of local varlist { 
	//generate locals of median and 95% bounds
	_pctile `var', nq(1000)
	local m_`var' = r(r500)
	local lb_`var' = r(r25) 
    local ub_`var' = r(r975) 	
}

//male
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRmalecem) result(`m_male') append 
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRmalecemlb) result(`lb_male') append
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRmalecemub) result(`ub_male') append
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRmaleconcem) result(`m_malecon') append 
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRmaleconcemlb) result(`lb_malecon') append
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRmaleconcemub) result(`ub_malecon') append
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRnmalecem) result(`m_N_male') round(0) append

//female
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRfemalecem) result(`m_female') append 
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRfemalecemlb) result(`lb_female') append
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRfemalecemub) result(`ub_female') append
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRfemaleconcem) result(`m_femalecon') append 
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRfemaleconcemlb) result(`lb_femalecon') append
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRfemaleconcemub) result(`ub_femalecon') append
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(KRnfemalecem) result(`m_N_female') round(0) append

********************************************************
********************************************************
********************************************************

********************************************************
*Mathisen
********************************************************
*FEMALE
*Need to open data each time, becuase observations dropped during CEM
program define Mcem_female

args Mathisen_Gender_CEM
use "`Mathisen_Gender_CEM'", clear

*drop missing differences
quietly: drop if dif_male_female==.

quietly: cem female_percfav if policyadopted!=., tr(dif_male_female) k2k
reg policyadopted female_percfav if cem_matched==1
mat define b = get(_b)
scalar bfemale = b[1,1]
scalar femalecon = b[1,2] //coef consstant
scalar N_female = e(N)
end

*MALE
*Need to open data each time, becuase observations dropped during CEM
program Mcem_male

args Mathisen_Gender_CEM
use "`Mathisen_Gender_CEM'", clear

*drop missing differences
quietly: drop if dif_male_female==.

quietly: cem male_percfav if policyadopted!=., tr(dif_male_female) k2k
reg policyadopted male_percfav if cem_matched==1

mat def results = r(table)
scalar bmale = results[1,1] //coef female_percfav
scalar malecon = results[1,2] //coef consstant
scalar N_male = e(N)
end

//set up a new dataset with variable names listed below called cem_data
tempfile Mcem_gender
tempname temp2
postfile `temp2' female  femalecon  N_female  ///
				male  malecon  N_male ///
				using "`Mcem_gender'", replace

*Set seed because CEM randomly drops duplicate matches
*https://www.random.org/
set seed 6951929
//run each program 1000 times 
forval i = 1/1000 {
	
Mcem_female "`Mathisen_Gender_CEM'"

Mcem_male "`Mathisen_Gender_CEM'"

//post results from each simulation to data set 
post `temp2' (bfemale) (femalecon) (N_female) ///
			(bmale) (malecon) (N_male) 

}
postclose `temp2' //write results to dataset 


******************************************************************************
*export results 
use "`Mcem_gender'", clear 


local varlist female femalecon N_female  ///
		male malecon N_male

foreach var of local varlist { 
	//generate locals of median and 95% bounds
	_pctile `var', nq(1000)
	local m_`var' = r(r500)
	local lb_`var' = r(r25) 
    local ub_`var' = r(r975) 	
}

//male
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mmalecem) result(`m_male') append 
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mmalecemlb) result(`lb_male') append
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mmalecemub) result(`ub_male') append
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mmaleconcem) result(`m_malecon') append 
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mmaleconcemlb) result(`lb_malecon') append
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mmaleconcemub) result(`ub_malecon') append
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mnmalecem) result(`m_N_male') round(0) append

//female
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mfemalecem) result(`m_female') append 
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mfemalecemlb) result(`lb_female') append
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mfemalecemub) result(`ub_female') append
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mfemaleconcem) result(`m_femalecon') append 
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mfemaleconcemlb) result(`lb_femalecon') append
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mfemaleconcemub) result(`ub_femalecon') append
`TEX'texresults2 using TxtFiles_NumericalResults\gender.txt, texmacro(Mnfemalecem) result(`m_N_female') round(0) append

********************************************************
********************************************************
